<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="../include/tag.jsp"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>${type == '1'?'关注回复':'自动回复'}</title>
    <%@include file="../include/commonFile.jsp"%>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
    <style type="text/css">
        .contentedit{
            height: 210px;
            resize: none;
            border: 0;
            font-size: 14px;
            line-height: 22px;
            padding: 16px;
            outline: 0;
            word-wrap: break-word;
            overflow-x: hidden;
            overflow-y: auto;
            -webkit-user-modify: read-write-plaintext-only;
            position: relative;
            border: solid 1px #e7e7eb;
        }
    </style>
</head><body>
<!--头部-->
<%@include file="../include/header.jsp"%>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp"%>
    <!--内容-->
    <section>
        <div class="section-main">
            <!-- 正文请写在这里 -->
            <div class="add-form-content">
                <form id="myForm" class="layui-form mt20" method="post" action="">
                    <input type="hidden" name="id" id="id" value="${response.id}" />
                    <input type="hidden" name="type" id="type" value="${type}" />
                    <%--目前只有文本类型--%>
                    <input type="hidden" name="replyType" id="replyType" value="text" />
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <textarea id="content" name="content" rows="15" cols="150" class="contentedit" lay-verify="content">${response.content}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
                        </div>
                    </div>
                </form>
            </div>

        </div><!--底部-->
        <%@include file="../include/footer.jsp"%>
    </section>
</div>

<script type="text/javascript" src="${ctx}/script/common/form_cache.js"></script>

<script>

    $(function () {

        layui.use(['form'], function() {
            var form = layui.form;

            //自定义验证规则
            form.verify({
                content : function(value) {
                    var content = $("#content").val();
                    console.log(content);
                    if (content == "") {
                        return "请填写回复的消息";
                    }
                }
            });

            //监听提交
            form.on('submit', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var formData = getFormData();
                    txz.ajaxRequest({
                        method: 'post',
                        url: '${ctx}/wechat/autoorattentionresponse/save.do',
                        params: formData,
                        callBack: function (res) {
                            typeof callBack === 'function' && callBack();
                            if (res.success) {
                                util.layerMsgSuccess("提交成功", function () {
                                    location.href = "${ctx}/wechat/autoorattentionresponse/view.do?type=${type}";
                                });
                            } else {
                                util.layerMsgError("提交失败")
                            }
                        }
                    })
                });
                return false;
            });
        });

    })

    function getFormData() {
        var formData = util.serializeForm($('#myForm').serializeArray());
        return formData;
    }
</script>
<c:if test="${type == '1'}">
    <script type="text/javascript">
        txz.initHeader({
            nav:[{
                name: '关注回复'
            }],
            info: '有新粉丝关注时，会自动发送信息'
        });
    </script>
</c:if>
<c:if test="${type == '2'}">
    <script type="text/javascript">
        txz.initHeader({
            nav:[{
                name: '自动回复'
            }],
            info: '当用户输入关键词以外的内容时，系统会自动回复以下信息'

        });
    </script>
</c:if>

</body>
</html>